<?php


namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Admin\Traits\AdminTrait;
use App\Http\Requests\Admin\BaseRequest;
use App\Models\Admin\AdminMenu;
use App\Models\Admin\Company;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Validator;

class IndexController extends AdminController
{
    use AdminTrait;
    public function index(BaseRequest $request)
    {
        $role_id=$this->jwt_user_info['role_id'];
        //根据角色，返回相应的菜单
        if($role_id==1)
        {
            $menu_list=AdminMenu::getMenu();
        }
        else
        {
            $menu_list=AdminMenu::getMenuByRoleId($role_id);
        }
        //返回用户信息
        $this->jwt_user_info->img_prefix=$this->getImgPrefix();
        $data=[
          'nav'=>$menu_list,
            'userInfo'=>$this->jwt_user_info,
        ];
        return $this->success($data);
    }

    public function getCompanyListByName(BaseRequest $request)
    {
        $input=$request->all();
        $rules=[
            'company_name'=>'string',
            'model'=>'integer',
        ];
        $validator = Validator::make($input, $rules,$this->vali_msg);
        if($validator->fails())
            return $this->error(['-1',$validator->errors()->first()]);
        $list=Company::getListByName($input);
        $data=[
            'list'=>$list,
        ];
        return  $this->success($data);
    }

}
